/*
 * Copyright 2006-2008 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package net.martinimix.beans.bind;

import java.util.Map;

/**
 * Provides a simple business object binder that always returns the
 * bean field name as the business object property.
 * 
 * @author Scott Rossillo
 *
 */
public class SimpleBusinessObjectBinder extends AbstractBusinessObjectBinder {

	private FieldPropertyMappingHandler fieldPropertyMapper;
	
	/**
	 * Constructs a new simple business object binder.
	 */
	public SimpleBusinessObjectBinder() { 
		super();
	}
	
	/**
	 * Creates a new simple business object binder with the given field property
	 * mapper.
	 * 
	 * @param fieldPropertyMapper the <code>FieldPropertyMapper</code> to use
	 * when binding fields to business object properties
	 */
	public SimpleBusinessObjectBinder(FieldPropertyMappingHandler fieldPropertyMapper) {
		super();
		this.fieldPropertyMapper = fieldPropertyMapper;
	}

	/*
	 * Always returns true; this binder supports binding any class.
	 * 
	 * @see net.martinimix.dao.bind.BusinessObjectBinder#supports(java.lang.Class)
	 */
	public boolean supports(Class clazz) {
		return true;
	}

	/* (non-Javadoc)
	 * @see net.martinimix.beans.bind.AbstractBusinessObjectBinder#fieldToPropertyMap(java.lang.Object)
	 */
	protected Map fieldToPropertyMap(Object bean) {
		
		return fieldPropertyMapper.mapFieldsToProperties(bean);
	}

	public FieldPropertyMappingHandler getFieldPropertyMapper() {
		return fieldPropertyMapper;
	}

	public void setFieldPropertyMapper(FieldPropertyMappingHandler fieldPropertyMapper) {
		this.fieldPropertyMapper = fieldPropertyMapper;
	}

}
